import {reqKeywordList, reqRealtimeKeywordList, reqSearch} from '@/api/index'

const state = {
    keywordList:[],
    realtimeKeywordList:[],
    goodsInfo:{}
}
const mutations = {
    SET_HOTSEARCHLIST(state,keywordList){
        state.keywordList = keywordList
    },
    SET_REALTIMEKEYWORDLIST(state,realtimeKeywordList){
        state.realtimeKeywordList = realtimeKeywordList
    },
    SET_GOODSINFO(state,goodsInfo){
        state.goodsInfo = goodsInfo
    }
}
const actions = {
    async getKeywordList({commit}){
        const result = await reqKeywordList()
        if (result.code === '200'){
            commit('SET_HOTSEARCHLIST',result.data)
        }
    },

    async getRealtimeKeywordList({commit},searchKeyword){
        const result = await reqRealtimeKeywordList(searchKeyword)
        if (result.code === '200'){
            commit('SET_REALTIMEKEYWORDLIST',result.data)
        }
    },

    async getSearch({commit},searchKeyword){
        const result = await reqSearch(searchKeyword)
        if (result.code === '200'){
            commit('SET_GOODSINFO',result.data)
        }
    }
}
const getters ={}

export default {
    state,
    mutations,
    actions,
    getters
}